package dfsketches.gas;

import java.util.Collection;
import java.util.HashMap;
import java.util.Vector;

public class PrimitiveGasMap implements GasMap {

	private int w, h, d;
	private boolean[][][] p;
	private HashMap<Gas, Gas> g;
	
	public PrimitiveGasMap(boolean[][][] pathes) {
		p = pathes;
		w = p.length;
		h = p[0].length;
		d = p[0][0].length;
		g = new HashMap<Gas, Gas>();
	}
	
	@Override
	public int getWidth() {
		return w;
	}

	@Override
	public int getHeight() {
		return h;
	}

	@Override
	public int getDepth() {
		return d;
	}

	@Override
	public boolean isGasPassable(int x, int y, int z) {
		return p[x][y][z];
	}

	@Override
	public int getConcentration(int gas, int x, int y, int z) {
		Gas gs = g.get(new Gas(x, y, z, gas, 0));
		if (gs == null)
			return 0;
		else
			return gs.c;
	}

	@Override
	public Collection<Gas> getConcentrations() {
		return new Vector<Gas>(g.values());
	}

	@Override
	public void setConcentration(int gas, int x, int y, int z, int concentration) {
		Gas gs = new Gas(x,y,z,gas,concentration);
		if (concentration > 0) {
			g.put(gs, gs);
		} else {
			g.remove(gs);
		}
	}

	@Override
	public void increaseConcentration(int gas, int x, int y, int z, int concentration) {
		Gas gs = new Gas(x,y,z,gas,concentration);
		Gas gi = g.get(gs);
		if (gi != null)
			gs.c += gi.c;
		g.put(gs, gs);
	}

}
